# coding=utf-8
from __future__ import unicode_literals

import os

from django.db import models

from recognition.utils import to_str


class CodeWhiteList(models.Model):
    """白名单"""

    code = models.CharField(max_length=100, unique=True)
    created_time = models.DateTimeField(auto_now_add=True)

    # block
    is_block = models.BooleanField(default=False)
    block_time = models.DateTimeField(null=True)

    class Meta:
        db_table = "wch_code_white_list"


def upload_to(instance, filename):
    return '/'.join([os.getcwd(), "/recognition/tf/image/", to_str(instance.code), filename])


class RegLog(models.Model):
    code = models.CharField(max_length=100)
    created_time = models.DateTimeField(auto_now_add=True)
    img = models.FileField(upload_to=upload_to)
    res = models.TextField(null=True)

    class Meta:
        db_table = "wch_reg_log"
